

const webpack=require('webpack');


const config=require('./webpack.config.dev');
const compiler=webpack(config);
const devMiddleware=require('webpack-dev-middleware');
let hotMiddleware=require('webpack-hot-middleware');
const devFunc=devMiddleware(compiler);

let hotFunc=hotMiddleware(compiler,{
    log:console.log,
    path:'/__webpack_hmr',
    heartbeat:2000
});


const express=require('express');
const app=express();

app.use(devFunc);
app.use(hotFunc);
app.use('/static',express.static('static'));

/*
compiler.plugin('compilation',function(compilation){
    console.log(compilation);
})*/


compiler.hooks.compilation.tap("html-webpack-plugin",function(HtmlwebpackPlugin){
    console.log('模块构建')
    HtmlwebpackPlugin.hooks.htmlWebpackPluginAfterEmit.tapAsync('hotFunc',function(data,cb){
        console.log('页面构建');
        console.log(hotFunc.publish)
        hotFunc.publish({ action: 'reload' });
        cb();
    });
});

app.listen(3000);